import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class BaseDao {

    private String driver;

    private String url;

    private String username;

    private String password;


    public   void getDataSource(){
        Properties properties=new Properties();
        ClassLoader classLoader = BaseDao.class.getClassLoader();
        InputStream resourceAsStream = classLoader.getResourceAsStream("db.properties");
        try {
            properties.load(resourceAsStream);
            String dataSource = properties.getProperty("driver");
            String url = properties.getProperty("url");
            String username = properties.getProperty("username");
            String password = properties.getProperty("password");
            this.driver=dataSource;
            this.url=url;
            this.driver=username;
            this.driver=password;
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void connection() throws Exception {
        Connection connection = DriverManager.getConnection(this.url, this.username, this.password);
        System.out.println(connection);
    }

    public static void main(String[] args) throws Exception {
        BaseDao baseDao=new BaseDao();
        baseDao.getDataSource();
        baseDao.connection();
    }

}
